﻿using CIS.Common.Grpc.Protos;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CIS.Common.Grpc
{
    public class GrpcMessage
    {
        public GrpcMessage()
        {
            Sender = new ClientInfo();
            Sender.ClientID = "2";
            Sender.ClientName = "Server";
        }

        public GrpcMessage(GrpcMessageData data)
        {
            if (data == null)
                return;
            Sender = new ClientInfo()
            {
                ClientID = data.Sender.ClientID,
                ClientName = data.Sender.ClientName
            };
            Name = data.Name;
            Topic = data.Topic;
            TransactionID = data.TransactionID;
            Timestamp = data.Timestamp;
            Data = data.Data;
            IsRequest = data.IsRequest;
        }
        public ClientInfo? Sender { get; set; }

        public string? Name { get; set; } = string.Empty;

        public string? Topic { get; set; } = "1";

        public string? TransactionID {  get; set; }=Guid.NewGuid().ToString();

        public string? Timestamp {  get; set; }=DateTime.Now.ToString();

        public string? Data { get; set; }

        public bool IsRequest {  get; set; }=true;

        public GrpcMessageData GetData()
        {
            GrpcMessageData grpcMessageData = new GrpcMessageData();
            grpcMessageData.Sender = new ClientInfoRequest();
            grpcMessageData.Sender.ClientID = this.Sender.ClientID;
            grpcMessageData.Sender.ClientName = this.Sender.ClientName;
            grpcMessageData.Name= this.Name;
            grpcMessageData.Topic= this.Topic;
            grpcMessageData.TransactionID= this.TransactionID;
            grpcMessageData.Timestamp= this.Timestamp;
            grpcMessageData.Data= this.Data;
            grpcMessageData.IsRequest= this.IsRequest;
            return grpcMessageData;

        }
    }
}
